import { MidwayConfig } from '@midwayjs/core';
import { uploadWhiteList } from '@midwayjs/upload';
import { join } from 'path';
import { mongodb } from './config';


export default {
  // use for cookie sign key, should change to your own and keep security
  keys: '1680763521942_8939',
  koa: {
    port: 7001,
  },
  mongoose: {
    dataSource: {
      default: {
        uri: mongodb.uri,
        options: {
          useNewUrlParser: true,
          useUnifiedTopology: true,
          user: mongodb.username,
          pass: mongodb.password,
        },
        // 关联实体
        entities: ['**/entity/*{.ts,.js}']
      }
    }
  },
  cors: {
    credentials: false,
  },
  jsonp: {
    callback: 'jsonp',
    limit: 512,
  },
  // redis: {
  //   client: {
  //     port: 6379, // Redis port
  //     host: "127.0.0.1", // Redis host
  //     password: "",
  //     db: 0,
  //   },
  // },
  bull: {
    // 默认的队列配置
    defaultQueueOptions: {
      redis: {
        port: 6379,
        host: '127.0.0.1',
        password: '',
      },
    }
  },
  jwt: {
    secret: 'with_hope717171717171', // fs.readFileSync('xxxxx.key')
    expiresIn: '1d', // https://github.com/vercel/ms
  },
  upload: {
    // mode: UploadMode, 默认为file，即上传到服务器临时目录，可以配置为 stream
    mode: 'stream',
    // fileSize: string, 最大上传文件大小，默认为 10mb
    fileSize: '10mb',
    // whitelist: string[]，文件扩展名白名单
    whitelist: uploadWhiteList.filter(ext => ext !== '.pdf'),
    // tmpdir: string，上传的文件临时存储路径
    tmpdir: join('./', 'midway-upload-files'),
    // cleanTimeout: number，上传的文件在临时目录中多久之后自动删除，默认为 5 分钟
    cleanTimeout: 5 * 60 * 1000,
    // base64: boolean，设置原始body是否是base64格式，默认为false，一般用于腾讯云的兼容
    base64: false,
    // 仅在匹配路径到 /upload 的时候去解析 body 中的文件信息
    match: /\/upload/,
  },
  view: {
    defaultViewEngine: 'nunjucks',
  },
} as MidwayConfig;
